package com.colin.orderservice10001.controller;

import com.colin.common.bean.Order;
import com.colin.common.response.R;
import com.colin.orderservice10001.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class OrderController {

    @Autowired
    private OrderService orderService;

    /**
     * 创建订单
     * @param order 订单数据
     *              orderComment
     *              orderPrice
     *              userId
     *              productId
     *              productCount
     * @return R
     *         data: orderNum
     */
    @PostMapping("/order")
    public R<String> createOrder(@RequestBody Order order) {
        return orderService.createOrder(order);
    }

    /**
     * 根据订单号获取订单数据
     * @param orderNum 订单号 ORDER_时间戳_用户id
     * @return R
     *         data: order
     */
    @GetMapping("/order/{orderNum}")
    public R<Order> getOrder(@PathVariable String orderNum) {
        return orderService.getOrder(orderNum);
    }

    /**
     * 修改订单状态
     * @param orderNum 订单号 ORDER_时间戳_用户id
     * @param orderStatus 订单状态
     *                    public final static Integer CREATED = 0;
     *                    public final static Integer PAID = 1;
     *                    public final static Integer CLOSED = 2;
     * @return R
     *         data: boolean
     */
    @PutMapping("/order/{orderNum}/{orderStatus}")
    public R<Boolean> changeOrderStatus(@PathVariable String orderNum, @PathVariable Integer orderStatus) {
        return orderService.changeOrderStatus(orderNum, orderStatus);
    }

}
